package hot100;

public class k3_在排序数组中查找元素的第一个和最后一个位置 {
    public int[] searchRange(int[] nums, int target) {
        int start = search(nums,target);
        if(start == nums.length || nums[start] != target){
            return new int[]{-1,-1};
        }
        int end = search(nums,target + 1) - 1;
        return new int[]{start,end};
    }
    private int search(int[] nums, int target){
        int left = 0;
        int right = nums.length - 1;
        while (left <= right){
            int mid = (left + right) >>> 1;
            if(nums[mid] < target){
                left = mid + 1;
            }else {
                right = mid - 1;
            }
        }
        return left;
    }
}
